// index.js
// 获取应用实例
import {request} from "../../utils/request"

const app = getApp()

Page({
  data: {
    userName: '',
    pwd: ''
  },
  onLoad() {
  },
  userNameInput(e) {
    const userName = e.detail.value
    this.setData({
      userName
    }) 
  },
  pwdInput(e) {
    const pwd = e.detail.value
    this.setData({
      pwd
    }) 
  },
  gotoIndexPage() {
    var that = this
    setTimeout(function() {
      request({
        url: "/user/login",
        method: 'POST',
        data: {
          account: that.data.userName,
          pwd: that.data.pwd
        }
      })
      .then(res => {
        console.log(res)
        app.globalData.token = res.data.data
        console.log('login', app.globalData.token)
        if(res.data.code === 200) {
          wx.navigateTo({
            url: '/pages/index/index',
          })
        } else {
          wx.showToast({
            title: res.data.message,
            icon: 'none',
            mask: true,
          })

        }
      })
    }, 100)
  },
  gotoRegister() {
    wx.navigateTo({
      url: '/pages/register/register',
    })
  }
})
